$(function () {

    //初始化表格
    initTable();
});


function initTable() {
    var options = {
        url: prefix + "/list",
        sortName: "createTime",
        sortOrder: "desc",
        search: false,
        showExport: false,
        columns: [{
            checkbox: true
        },{
            field: 'tableName',
            title: '表名称',
            sortable: true
        },{
            field: 'tableComment',
            title: '表注释',
            sortable: true
        },{
            field: 'userName',
            title: '用户名',
            sortable: true
        },{
            field: 'createTime',
            title: '创建时间',
            sortable: true
        },{
            title: '操作',
            align: 'center',
            formatter: function(value, row, index) {
                var msg = '<a class="btn btn-primary btn-xs" href="#" onclick="genCode(\'' + row.tableName + '\')"><i class="fa fa-bug"></i>生成代码</a> ';
                return msg;
            }
        }]
    }
    $.table.init(options);
}

// 生成代码
function genCode(tableName) {
    $.modal.confirm("确定要生成" + tableName + "表代码吗？", function() {
        location.href = prefix + "/genCode/" + tableName;
        layer.msg('执行成功,正在生成代码请稍后…', { icon: 1 });
    })
}

//批量生成代码
function batchGenCode() {
    var rows = $.table.getColumns("tableName");
    if (rows.length == 0) {
        $.modal.alertWarning("请选择要生成的数据");
        return;
    }
    $.modal.confirm("确认要生成选中的" + rows.length + "条数据吗?", function() {
        location.href = prefix + "/batchGenCode?tables=" + rows;
        layer.msg('执行成功,正在生成代码请稍后…', { icon: 1 });
    });
}